<script src="../../../.eslintrc.js"></script>
<template>
  <div class="login-container">
    <el-row :gutter="20">
      <el-col :span="6" :offset="3">
        <div class="grid-content bg-purple">
          写点什么好呢
        </div>
      </el-col>
      <el-col :span="6" :offset="7">
        <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">

          <div class="title-container">
            <p class="title">Hello !</p>
            <span>欢迎来到大鹏教育开发者管理平台！</span>
          </div>

          <el-form-item prop="principal">
            <span class="svg-container">
              <svg-icon icon-class="user" />
            </span>
            <el-input
              ref="principal"
              v-model="loginForm.principal"
              placeholder="用户名"
              name="principal"
              type="text"
              tabindex="1"
              auto-complete="on"
            />
          </el-form-item>

          <el-form-item prop="credentials">
            <span class="svg-container">
              <svg-icon icon-class="password" />
            </span>
            <el-input
              :key="loginForm.loginType"
              ref="password"
              v-model="loginForm.credentials"
              type="password"
              placeholder="密码"
              name="credentials"
              tabindex="2"
              auto-complete="on"
              @keyup.enter.native="handleLogin"
            />
            <span class="show-pwd" @click="showPwd">
              <svg-icon :icon-class="loginForm.loginType === 'ACCOUNT' ? 'eye' : 'eye-open'" />
            </span>
          </el-form-item>

          <el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">登 录</el-button>

        </el-form>
      </el-col>
    </el-row>

  </div>
</template>

<script>
//你能看到的话说明你是前后端大神哦 厉害~厉害~  admin 密码 zbNvalEllkNNVCY0
export default {
  name: 'Login',
  data() {
    const validatePassword = (rule, value, callback) => {
      if (value.length < 6) {
        callback(new Error())
      } else {
        callback()
      }
    }
    return {
      loginForm: {
        principal: '',
        credentials: '',
        loginType: 'ACCOUNT',
        source: "PC_HT"
      },
      loginRules: {
        principal: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
        credentials: [{ required: true, trigger: 'blur', message: '密码不能少于6位', validator: validatePassword }]
      },
      loading: false,
      redirect: undefined
    }
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    showPwd() {
      if (this.loginType === 'ACCOUNT') {
        this.loginType = ''
      } else {
        this.loginType = 'ACCOUNT'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true
          this.$store.dispatch('user/login', this.loginForm).then(() => {
            this.$router.push({ path: this.redirect || '/' })
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss">
/* reset element-ui css */
.title-container {
  margin-bottom: 30px;
  .title{
    font-size: 3em;
  }
}
.login-container {
  background:  url('~@/assets/background.jpeg') center center fixed;
  .el-row {
    margin-top: 10%;
  }
  .el-input {
    display: inline-block;
    height: 55px;
    width: 85%;

    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      padding: 12px 5px 12px 15px;
      height: 55px;
    }
  }

  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background-color: #e8f0fe;
    border-radius: 5px;
    color: #000000;
  }

  .el-button {
    height: 50px;
  }

  .international{
    font-size: 18px;
  }
}

.login-container {
  min-height: 100%;
  width: 100%;
  overflow: hidden;

  .login-form {
    width: 470px;
    overflow: hidden;
  }

  .tips {
    font-size: 14px;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
  }
}
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-transition: color 9999s ease-out, background-color 9999s ease-out;
  -webkit-transition-delay: 9999s;
}
</style>
